// DemoApplication.java
import org.zjx.core.*;
import org.zjx.core.controller.*;
import org.zjx.core.state.*;

import java.time.Instant;
import java.util.Collection;
import java.util.List;
import java.util.Optional;

/**
 * 演示主程序
 */
public class DemoApplication {
    public static void main(String[] args) {
        // 初始化控制器
        GameController controller = new GameController();

        // 初始状态版本号
        long baseVersion = 0;

        // 模拟游戏循环
        for (int i = 0; i < 10; i++) {

            try {
                // 处理动作
                controller.processAction("player1");

                // 轮询结果
                StateAccessor accessor = new StateAccessor() {
                    @Override
                    public <T extends StateComponent> Optional<T> getComponent(Class<T> type) {
                        return Optional.empty();
                    }

                    @Override
                    public Collection<StateComponent> getAllComponents() {
                        return List.of();
                    }

                    @Override
                    public <T extends StateComponent> void registerComponent(Class<T> type, T component) {

                    }

                    @Override
                    public <T extends StateComponent> void removeComponent(Class<T> type) {

                    }
                };
                Optional<GameAction> action = controller.pollAction("player1", accessor);

                int finalI = i;
                action.ifPresent(a -> System.out.println("Round " + finalI + " Action: " + a.getActionId()));
            } catch (Exception e) {
                System.err.println("Error in round " + i + ": " + e.getMessage());
                e.printStackTrace();
            }
        }
    }
}